<?php
	namespace org\kahikai\database\mysql;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Cp1252"/>
<meta name="author" content="Ch4mp"/>
<link rel="shortcut icon" href="../../../../../favicon.ico" type="image/x-icon"/> 
<link rel="icon" href="../../../../../favicon.ico" type="image/x-icon"/>
<title>MysqlPhylogenyDao test</title>
</head>
<body>
<?php
	require_once '../../../../../org/kahikai/database/mysql/MysqlPhylogenyDao.php';
	
	use org\kahikai\database\mysql\MysqlPhylogenyDao;
	
	$phylogenyDao = new MysqlPhylogenyDao();
	
	function printPhylogenyTree($phylogeny, $indent) {
		if(!isset($phylogeny)) {
			echo "<tr/>\n";
			return;
		}
		echo "<tr>";
		for($i=0; $i<$indent; $i++) {
			echo "<td/>";
		}
		echo "<td>$phylogeny->name:</td></tr>\n";
		foreach($phylogeny->childs as $child) {
			printPhylogenyTree($child, $indent + 1);
		}
	}
	
	function printPhylogenyBackward($phylogeny, $source) {
		if(!isset($phylogeny)) {
			echo 'null';
			return;
		}
		echo "$source: ($phylogeny->id; $phylogeny->name)";
		$tmp = $phylogeny->parent;
		while($tmp != null) {
			echo " => ($tmp->id; $tmp->name)";
			$tmp = $tmp->parent;
		}
	}
	
	echo "<h1>getSources()</h1>\n";
	echo "<p>";
	foreach($phylogenyDao->getSources() as $source) {
		echo "$source<br/>\n";
	}
	echo "</p>\n";
	
	echo "<h1>getAllSpeciesLeaves()</h1>\n";
	foreach($phylogenyDao->getAllSpeciesLeaves() as $speciesId => $phylogenies) {
		echo "<h2>Species#$speciesId</h2>\n<p>\n";
		foreach($phylogenies as $source => $phylogeny) {
			printPhylogenyBackward($phylogeny, $source);
			echo "<br/>\n";
		}
		echo "</p>\n";
	}
	
?>
</body>
</html>